//---------------------------------------------------------------------
// Author: Keith Hill
//
// Description: Class to implement the Convert-FromBase64 cmdlet.
//
// Creation Date: Aug 20, 2006
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Management.Automation;

namespace Pscx.Commands.Text
{
    [Cmdlet(VerbsData.ConvertFrom, "Base64"),
     Description("Converts base64 encoded string to byte array."),
     RelatedLinks("ConvertTo-Base64")]
    public class ConvertFromBase64Command : Cmdlet
    {
        private List<string> _text = new List<string>();

        [AllowEmptyCollection, AllowNull,
         Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true,
                   HelpMessage="Base64 encoded string to be converted into byte arary.")]
        public string[] Base64Text
        {
            get { return _text.ToArray(); }
            set { _text.AddRange(value); }
        }

        protected override void EndProcessing()
        {
            string base64 = String.Concat(_text.ToArray());
            byte[] bytes = Convert.FromBase64String(base64);
            WriteObject(bytes);
        }
    }
}